package bavaria.hightec.banking;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import bavaria.hightec.formatter.*;

public class Statement {
	
	private Map<String, StatementFormatter> mime = new HashMap<String, StatementFormatter>();
		
	public Statement() throws IOException{
		Properties props = new Properties();
		InputStream in = new FileInputStream("formatter.properties");
		props.load(in);
		String plainText = props.getProperty("text/plain");
		String htmlText = props.getProperty("text/html");
		try {
			StatementFormatterPlainTextImpl plain = (StatementFormatterPlainTextImpl) Class.forName(plainText).newInstance();
			StatementFormatterHTMLTextImpl html = (StatementFormatterHTMLTextImpl) Class.forName(htmlText).newInstance();		
			
			mime.put("text/plain", plain);
			mime.put("text/html", html);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public StatementFormatter getStatement(String mimeType){
		return mime.get(mimeType);
	}
	
	
}
